<template>
  <div>
    <div id="table-area">
      <h2>我负责的活动</h2>
      <el-table
        :loading="listLoading"
        :data="list"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          align="center"
          prop="actId"
          label="活动编号"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="actTitle"
          label="活动名称"
          width="200px"
        />

        <el-table-column
          align="center"
          prop="actType"
          label="活动级别"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actType=='1'">学部级</span>
            <span v-if="scope.row.actType=='2'" style="color: blue;"><b>校级</b></span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="actMemberMax"
          label="活动人数"
          width="100px"
        />

        <el-table-column
          align="center"
          prop="actPrincipalName"
          label="活动负责人"
          width="120px"
        />

        <el-table-column
          align="center"
          prop="actPrincipalPhone"
          label="负责人电话"
          width="150px"
        />

        <el-table-column
          align="center"
          prop="actAddress"
          label="活动地点"
          width="300px"
        />

        <el-table-column
          align="center"
          prop="actMemberWay"
          label="录取方式"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actMemberWay=='1'">手动审核</span>
            <span v-if="scope.row.actMemberWay=='2'">无需审核</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="actStatus"
          label="活动状态"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.actStatus=='0'">待审核</span>
            <span v-if="scope.row.actStatus=='1'">报名中</span>
            <span v-if="scope.row.actStatus=='2'">已截止</span>
            <span v-if="scope.row.actStatus=='3'">已结束</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作">
          <template slot-scope="Scope">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="getActivityInfo(Scope.row.actId)">详细</el-button>
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="getApplyList(Scope.row.actId)">报名录取</el-button>
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="getAdmittedApply(Scope.row.actId)">人员名单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <activity-info ref="info" :act-id="actId" :show="show" />
    <apply-list ref="applylist" :act-id="actId" :show="show" />
    <admitted-apply ref="admittedApply" :act-id="actId" :show="show" />
  </div>
</template>

<script>
import { getActivityByUser } from '../../api/act.js'
import Info from '../../components/activity/info.vue'
import ApplyList from '../../components/apply/apply_list.vue'
import AdmittedApply from '../../components/apply/admittedApply.vue'
export default {
  name: '',
  // import引入的组件需要注入到对象中才能使用
  components: {
    'activity-info': Info,
    'apply-list': ApplyList,
    'admitted-apply': AdmittedApply
  },
  data() {
    // 这里存放数据
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 10, //    每页的数据条数
      list: [],
      actId: '',
      show: false,
      dialogFormVisible: false,
      search: {},
      listLoading: false

    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.fetchData()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    handleSizeChange: (size) => {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: (currentPage) => {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    getActivityInfo(actId) {
      this.$refs.info.showInfo(actId)
    },
    getApplyList(actId) {
      this.$refs.applylist.showList(actId)
    },
    getAdmittedApply(actId) {
      this.$refs.admittedApply.showList(actId)
    },
    fetchData() {
      getActivityByUser().then((resp) => {
        this.list = resp.obj
      })
    }

  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style>
  #table-area{
      margin-left: 10px;
      margin-right: 10px;
  }
</style>
